﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_nhapkhoInfo
    {
        private int _id_lannhap;
        private string _sohd;
        private DateTime _ngaynhap;
        private int _nguoinhap;
        private int _makho;
        private string _noidung;
        private string _ghichu;
        private int _manx;
        private int _id_hd;
        private int _trangthai;
        private int _khoxuat;

        public cs_erp_nhapkhoInfo()
        {
            this._id_lannhap = 0;
            this._sohd = " ";
            this._ngaynhap = Convert.ToDateTime("01/01/9999");
            this._nguoinhap = 0;
            this._makho = 0;
            this._noidung = " ";
            this._ghichu = " ";
            this._manx = 0;
            this._id_hd = 0;
            this._trangthai = 0;
            this._khoxuat = 0;
        }
        public int id_lannhap
        {
            get
            {
                return this._id_lannhap;
            }
            set
            {
                this._id_lannhap = value;
            }
        }
        public string sohd
        {
            get
            {
                return this._sohd;
            }
            set
            {
                this._sohd = value;
            }
        }
        public DateTime ngaynhap
        {
            get
            {
                return this._ngaynhap;
            }
            set
            {
                this._ngaynhap = value;
            }
        }
        public int nguoinhap
        {
            get
            {
                return this._nguoinhap;
            }
            set
            {
                this._nguoinhap = value;
            }
        }
        public int makho
        {
            get
            {
                return this._makho;
            }
            set
            {
                this._makho = value;
            }
        }
        public string noidung
        {
            get
            {
                return this._noidung;
            }
            set
            {
                this._noidung = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }
        public int manx
        {
            get
            {
                return this._manx;
            }
            set
            {
                this._manx = value;
            }
        }
        public int id_hd
        {
            get
            {
                return this._id_hd;
            }
            set
            {
                this._id_hd = value;
            }
        }

        public int trangthai
        {
            get
            {
                return this._trangthai;
            }
            set
            {
                this._trangthai = value;
            }
        }

        public int khoxuat
        {
            get
            {
                return this._khoxuat;
            }
            set
            {
                this._khoxuat = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[12];
            paraName[0] = "@id_lannhap";
            paraName[1] = "@sohd";
            paraName[2] = "@ngaynhap";
            paraName[3] = "@nguoinhap";
            paraName[4] = "@makho";
            paraName[5] = "@noidung";
            paraName[6] = "@ghichu";
            paraName[7] = "@manx";
            paraName[8] = "@id_hd";
            paraName[9] = "@trangthai";
            paraName[10] = "@khoxuat";
            paraName[11] = "@option";
            object[] paraValue = new object[12];
            paraValue[0] = this._id_lannhap;
            paraValue[1] = this._sohd;
            paraValue[2] = this._ngaynhap;
            paraValue[3] = this._nguoinhap;
            paraValue[4] = this._makho;
            paraValue[5] = this._noidung;
            paraValue[6] = this._ghichu;
            paraValue[7] = this._manx;
            paraValue[8] = this._id_hd;
            paraValue[9] = this._trangthai;
            paraValue[10] = this._khoxuat;
            paraValue[11] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 12, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }

        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_NHAPKHO", option);
        }

        
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_NHAPKHO", "id_hd = " + this._id_hd);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_lannhap = Convert.ToInt32(ds.Tables[0].Rows[0]["id_lannhap"].ToString().Trim());
                this._sohd = ds.Tables[0].Rows[0]["sohd"].ToString().Trim();
                this._ngaynhap = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaynhap"].ToString().Trim());
                this._nguoinhap = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhap"].ToString().Trim());
                this._makho = Convert.ToInt32(ds.Tables[0].Rows[0]["makho"].ToString().Trim());
                this._noidung = ds.Tables[0].Rows[0]["noidung"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._manx = Convert.ToInt32(ds.Tables[0].Rows[0]["manx"].ToString().Trim());
                this._id_hd = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hd"].ToString().Trim());
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public int Get_Info_1()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_NHAPKHO", "sohd = N'" + this._sohd + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_lannhap = Convert.ToInt32(ds.Tables[0].Rows[0]["id_lannhap"].ToString().Trim());
                this._sohd = ds.Tables[0].Rows[0]["sohd"].ToString().Trim();
                this._ngaynhap = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaynhap"].ToString().Trim());
                this._nguoinhap = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhap"].ToString().Trim());
                this._makho = Convert.ToInt32(ds.Tables[0].Rows[0]["makho"].ToString().Trim());
                this._noidung = ds.Tables[0].Rows[0]["noidung"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._manx = Convert.ToInt32(ds.Tables[0].Rows[0]["manx"].ToString().Trim());
                this._id_hd = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hd"].ToString().Trim());
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public int Get_Info_by_NK()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_NHAPKHO", "id_lannhap = " + this._id_lannhap);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_lannhap = Convert.ToInt32(ds.Tables[0].Rows[0]["id_lannhap"].ToString().Trim());
                this._sohd = ds.Tables[0].Rows[0]["sohd"].ToString().Trim();
                this._ngaynhap = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngaynhap"].ToString().Trim());
                this._nguoinhap = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhap"].ToString().Trim());
                this._makho = Convert.ToInt32(ds.Tables[0].Rows[0]["makho"].ToString().Trim());
                this._noidung = ds.Tables[0].Rows[0]["noidung"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._manx = Convert.ToInt32(ds.Tables[0].Rows[0]["manx"].ToString().Trim());
                this._id_hd = Convert.ToInt32(ds.Tables[0].Rows[0]["id_hd"].ToString().Trim());
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.id_lannhap, a.sohd, a.ngaynhap, d.hoten, a.makho, a.noidung, a.ghichu, a.manx, c.tennhapxuat, a.id_hd, a.trangthai, b.tentrangthai "
                + " from ERP_NHAPKHO a, ERP_NHAPKHO_TRANGTHAI b, ERP_NHAPXUAT c, HMR_NHANVIEN d"
                + " where b.id_trangthai = a.trangthai and c.manx = a.manx and a.nguoinhap = d.manhanvien";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}